//
//  TMGStoreDetailViewController.m
//  TMGold
//
//  Created by Mac on 2018/4/17.
//  Copyright © 2018年 tangmu. All rights reserved.
//

#import "TMGStoreDetailViewController.h"
#import "NSString+STMD5.h"
@interface TMGStoreDetailViewController ()<STActionSheetDelegate>

@end

@implementation TMGStoreDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"商品详情";
    [self configSubView];
    [self configFooterAndBottomView];
    // Do any additional setup after loading the view.
}
#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 300)];
    header.backgroundColor = [UIColor whiteColor];
    
    UIImageView * banner = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 250)];
    banner.image = [UIImage imageNamed:@"新手特权金banner"];
    [header addSubview:banner];
    
    [banner sd_setImageWithURL:[NSURL URLWithString:_model.picture_detail] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
    }];
    STLabel *moneyLable = [[STLabel alloc] initWithFrame:CGRectMake(15, banner.bottom, UIScreenWidth - 30, 40)
                                                    text:[NSString stringWithFormat:@"￥%@",_model.money]
                                               textColor:TM_redColor
                                                    font:13
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    [header addSubview:moneyLable];
    
    
    STLabel *  titleLable = [[STLabel alloc] initWithFrame:CGRectMake(15, moneyLable.bottom, UIScreenWidth - 30, 35)
                                                text:_model.title
                                           textColor:FirstTextColor
                                                font:12
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];
    [NSString lableAutoAdjustheightWithLabel:titleLable];
    [header addSubview:titleLable];
    
    header.height = titleLable.bottom + 10;
    self.tableView.tableHeaderView = header;

}
- (void)configFooterAndBottomView{
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 49)];
    self.tableView.tableFooterView = footer;
    __weak typeof(self) weakSelf =  self;
    UIView * bootomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 49)];
    bootomView.top = [TMUtils tabBarTop];
    bootomView.backgroundColor = [UIColor whiteColor];
    [bootomView st_showTopShadow];
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 49)
                                                     title:@"立即购买"
                                                titleColor:[UIColor whiteColor]
                                                 titleFont:18
                                              cornerRadius:0
                                           backgroundColor:TM_orangeColor
                                           backgroundImage:nil
                                                     image:nil];
    buyButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [bootomView addSubview:buyButton];
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [buyButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedConnectButton];
    }];
    [self.view addSubview:bootomView];
}
#pragma mark --Action Method
- (void)onSelectedConnectButton{
    //点击联系客服
    TMGUserModel * user = [STUserManger defult].loginUser;
//    user.pwd = @"123456";
    LBPassWordPresentViewController * passwordVC = [LBPassWordPresentViewController new];
    passwordVC.pwd = user.pwd;
    [passwordVC setPwdDidEdited:^(LBPassWordPresentViewController *vc, NSString *inputPwd) {
        if (![inputPwd.st_md532BitLower isEqualToString:user.pwd]) {
            [vc rightLablebackAnimation];
        }else{
            [vc dismissWithHandle:^{
                [SVProgressHUD showSuccessWithStatus:@"购买成功"];
                [self.navigationController popViewControllerAnimated:YES];
            }];
        }
    }];
    [self presentViewController:passwordVC animated:NO completion:nil];
    return;
    STActionSheet * action = [[STActionSheet alloc] initWithTitle:nil buttonTitles:@[@"在线客服",@"拨打电话"] cancelTitle:@"取消" delegate:self];
    [action show];
}
#pragma mark --STActionSheetDelegate
- (void)actionSheet:(STActionSheet *)actionSheet didClickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        [TMUtils gotoCustomServiceViewController];
    }
    if (buttonIndex == 1) {
        //拨打电话
        NSMutableString* str = [[NSMutableString alloc] initWithFormat:@"telprompt://%@",serviceCustomPhpne];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }
}
@end
